<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2020-06-22
 * Time: 23:13
 */

namespace app\api\controller\v1;

use app\api\model\Member as MemberModel;
use app\api\model\User;
use app\api\model\Withdrawal as WithdrawalModel;
use app\api\service\withdrawal\WithdrawalSer;
use LinCmsTp5\exception\ParameterException;
use think\facade\Request;

class Withdrawal
{
    /**
     * 获取列表
     * @validate('PagingParameter')
     * @auth('提现列表','会员管理')
     */
    public function getDataList($page,$limit,$type)
    {
        if($type) {
            $query = WithdrawalModel::where('type','eq',$type)
                ->order('id desc');
        } else {
            $query = WithdrawalModel::order('id desc');
        }
        $count = $query->count();
        $result = $query->page($page, $limit)->select()->each(function ($item){
            if($item['type'] == 1) {
                $item['type_name'] = '会员';
            } elseif ($item['type'] == 2) {
                $item['type_name'] = '省级合伙人';
            } elseif ($item['type'] == 3) {
                $item['type_name'] = '市级合伙人';
            } elseif ($item['type'] == 4) {
                $item['type_name'] = '区/县级合伙人';
            } elseif ($item['type'] == 5) {
                $item['type_name'] = '助理';
            }
            if($item['status'] == 1) {
                $item['status_name'] = '未审核';
            } elseif ($item['status'] == 2) {
                $item['status_name'] = '已审核';
            }
        });
        $data['count'] = $count;
        $data['data'] = $result;
        return $data;
    }

    /**
     * 审核通过
     */
    public function updateData($id)
    {
        $Withdrawal = new WithdrawalSer($id);
        return $Withdrawal->entrance();
    }
}